<?php

namespace app\common\service;

use app\common\service\Base;
use app\common\model\Message as MessageModel;

class Message extends Base
{

    public function __construct()
    {
        parent::__construct();
        $this->currentModel = new MessageModel();
    }

    /**
     * 我的留言列表
     * @param $customerId
     * @return array|\PDOStatement|string|\think\Collection
     */
    public function getMessageListByCustomerId($customerId) {

        $map['m.mch_customer_id'] = $customerId;
        $map['m.is_del'] = config('enum.messageIsDel.valid.value');

        $list = $this->currentModel->alias("m")
            ->field("0 as owner, m.id message_id, m.message, m.create_time as time, c.nickname, 
                    c.headimgurl, c.id customer_id")
            ->leftJoin("__CUSTOMER__ c", "m.consume_customer_id = c.id")
            ->where($map)
            ->order("m.id desc")
            ->select();

        return $list;
    }

}